#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>

int main()
{
  pid_t id = fork();

  if (id == 0)
  {
    //子进程
    int cnt = 5;
    while (cnt)
    {
      printf("I am child process. I have %d seconds to exit. pid:%d  ppid:%d\n", cnt--, getpid(), getppid());
      sleep(1);
    }
    if (1) exit(111);
    exit(0);
  }
 
  //父进程
  sleep(10);
  pid_t ret_id = wait(NULL);
  if (ret_id > 0)
  {
  printf("I am father process. Wait for sucess! pid:%d  ppid:%d\n", getpid(), getppid());
  }
  sleep(5);
  return 0;
}
